#include <cgic.h>
#include <glib.h>

int cgiMain(){

    char gatewayIp[128];
    char location[128];
    cgiFormString("gatewayIp",gatewayIp,128);
    cgiFormString("location",location,128);

    //从配置文件中获取路径
    GKeyFile *file=g_key_file_new();
    g_key_file_load_from_file(file,"../config/config.ini",G_KEY_FILE_NONE,NULL);
    gchar *path=g_key_file_get_string(file,"config","deviceInfoPath",NULL);

    //使用glib保存ini配置文件
    GKeyFile *keyFile=g_key_file_new();
    g_key_file_set_string(keyFile,"config","gatewayIp",gatewayIp);
    g_key_file_set_string(keyFile,"config","location",location);
    g_key_file_save_to_file(keyFile,path,NULL);
    g_key_file_free(keyFile);

    cgiHeaderContentType("text/html");
    fprintf(cgiOut, "<HTML><HEAD> <meta charset=\"UTF-8\"> \n");
    fprintf(cgiOut, "<TITLE>cgic测试</TITLE></HEAD>\n");
    fprintf(cgiOut, "<BODY><H1>获取数据成功!</H1>\n"); 
    fprintf(cgiOut,"</BODY></HTML>");
    return 0;
}